using AutoMapper;
using S.M.SmartMedical.API.Write.Application.Command;
using S.M.SmartMedical.Domain.DTOs;
using S.M.SmartMedical.Domain.Entities;
using S.M.SmartMedical.Domain.Enums;

namespace S.M.SmartMedical.API.Write
{
    /// <summary>
    /// AutoMapper映射配置
    /// </summary>
    public class MapperProfiles : Profile
    {
        /// <summary>
        /// 构造函数，配置映射规则
        /// </summary>
        public MapperProfiles()
        {
            // User实体到UserInfoDto的映射
            CreateMap<User, UserInfoDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.UserName))
                .ForMember(dest => dest.RealName, opt => opt.MapFrom(src => src.RealName))
                .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Phone))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status))
                .ForMember(dest => dest.LastLoginTime, opt => opt.MapFrom(src => src.LastLoginTime))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime));

            // OrderApplication实体到OrderApplicationResultDto的映射
            CreateMap<OrderApplication, OrderApplicationResultDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.ApplicationNumber, opt => opt.MapFrom(src => src.ApplicationNumber))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src => (int)src.Status))
                .ForMember(dest => dest.ProjectCount, opt => opt.MapFrom(src => src.ProjectCount))
                .ForMember(dest => dest.TotalAmount, opt => opt.MapFrom(src => src.TotalAmount))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime))
                .ForMember(dest => dest.Items, opt => opt.Ignore());

            // OrderApplicationItem实体到OrderApplicationItemResultDto的映射
            CreateMap<OrderApplicationItem, OrderApplicationItemResultDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.MedicalProjectId, opt => opt.MapFrom(src => src.MedicalProjectId))
                .ForMember(dest => dest.ProjectName, opt => opt.MapFrom(src => src.ProjectName))
                .ForMember(dest => dest.ProjectPrice, opt => opt.MapFrom(src => src.ProjectPrice))
                .ForMember(dest => dest.ProjectDescription, opt => opt.MapFrom(src => src.ProjectDescription))
                .ForMember(dest => dest.Quantity, opt => opt.MapFrom(src => src.Quantity))
                .ForMember(dest => dest.SubTotal, opt => opt.MapFrom(src => src.SubTotal));

            // CarouselCreateDto到Carousel实体的映射
            CreateMap<CarouselCreateDto, Carousel>()
                .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
                .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl))
                .ForMember(dest => dest.LinkUrl, opt => opt.MapFrom(src => src.LinkUrl))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status))
                .ForMember(dest => dest.SortOrder, opt => opt.MapFrom(src => src.Sort))
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.Uploader, opt => opt.Ignore())
                .ForMember(dest => dest.UploadTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateUserName, opt => opt.Ignore())
                .ForMember(dest => dest.IsDeleted, opt => opt.Ignore())
                .ForMember(dest => dest.EffectiveStartTime, opt => opt.Ignore())
                .ForMember(dest => dest.EffectiveEndTime, opt => opt.Ignore());

            // Carousel实体到CarouselDto的映射
            CreateMap<Carousel, CarouselDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
                .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl))
                .ForMember(dest => dest.LinkUrl, opt => opt.MapFrom(src => src.LinkUrl))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status))
                .ForMember(dest => dest.StatusName, opt => opt.MapFrom(src => src.Status.ToString()))
                .ForMember(dest => dest.Sort, opt => opt.MapFrom(src => src.SortOrder))
                .ForMember(dest => dest.Uploader, opt => opt.MapFrom(src => src.Uploader))
                .ForMember(dest => dest.UploadTime, opt => opt.MapFrom(src => src.UploadTime))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime));

            // HospitalArea实体到HospitalAreaDto的映射
            CreateMap<HospitalArea, HospitalAreaDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.Address))
                .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Phone))
                .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
                .ForMember(dest => dest.IsSelfServiceEnabled, opt => opt.MapFrom(src => src.IsSelfServiceEnabled))
                .ForMember(dest => dest.Longitude, opt => opt.MapFrom(src => src.Longitude))
                .ForMember(dest => dest.Latitude, opt => opt.MapFrom(src => src.Latitude))
                .ForMember(dest => dest.SortOrder, opt => opt.MapFrom(src => src.SortOrder))
                .ForMember(dest => dest.Tags, opt => opt.Ignore()) // Tags字段在Handler中单独处理
                .ForMember(dest => dest.Distance, opt => opt.Ignore()); // Distance字段在Handler中单独计算

            // HospitalCreateDto到Hospital实体的映射
            CreateMap<HospitalCreateDto, Hospital>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl))
                .ForMember(dest => dest.Level, opt => opt.MapFrom(src => src.Level))
                .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.Address))
                .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Phone))
                .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
                .ForMember(dest => dest.IsEnabled, opt => opt.MapFrom(src => src.IsEnabled))
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.Uploader, opt => opt.Ignore())
                .ForMember(dest => dest.UploadTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateUserName, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateTime, opt => opt.Ignore())
                .ForMember(dest => dest.UpdateUserName, opt => opt.Ignore())
                .ForMember(dest => dest.IsDeleted, opt => opt.Ignore());

            // HospitalUpdateDto到Hospital实体的映射
            CreateMap<HospitalUpdateDto, Hospital>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl))
                .ForMember(dest => dest.Level, opt => opt.MapFrom(src => src.Level))
                .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.Address))
                .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Phone))
                .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
                .ForMember(dest => dest.IsEnabled, opt => opt.MapFrom(src => src.IsEnabled));

            // Hospital到HospitalDto的映射
            CreateMap<Hospital, HospitalDto>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl))
                .ForMember(dest => dest.Level, opt => opt.MapFrom(src => src.Level))
                .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.Address))
                .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Phone))
                .ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
                .ForMember(dest => dest.IsEnabled, opt => opt.MapFrom(src => src.IsEnabled));
        }
    }
}
